package com.jiangyg.mall.coupon.service;

import com.jiangyg.mall.core.support.restful.Pagination;
import com.jiangyg.mall.coupon.dao.CouponSpuDao;
import com.jiangyg.mall.coupon.dto.CouponSpuDTO;
import com.jiangyg.mall.coupon.entity.CouponSpu;
import com.jiangyg.mall.coupon.vo.CouponSpuVO;
import com.jiangyg.mall.db.mybatis.BaseServiceImpl;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class CouponSpuServiceImpl extends BaseServiceImpl<CouponSpuDao, CouponSpu> implements CouponSpuService {

    @Autowired
    public CouponSpuServiceImpl(CouponSpuDao couponSpuDao) {
        super(couponSpuDao);
    }

    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
    public Pagination<CouponSpuVO> selectPagination(Pagination<CouponSpuVO> pagination) throws Exception {
        return this.executeSelectPagination(pagination, CouponSpuVO.class);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean saveOrUpdate(CouponSpuDTO dto) throws Exception {
        return this.executeSaveOrUpdate(dto) > 0;
    }

    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
    public CouponSpuVO selectById(Long couponSpuId) throws Exception {
        return this.executeSelectById(couponSpuId, CouponSpuVO.class);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean delete(List<Long> couponSpuIds) {
        return this.baseMapper.deleteBatchIds(couponSpuIds) > 0;
    }

}
